package com.neusoft.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
import com.neusoft.po.User;
import com.neusoft.po.UserGet;
import com.neusoft.service.UserService;

@RestController
@RequestMapping("/User")
@RefreshScope //开启动态刷新
public class UserController {

	@Autowired
	private UserService userService;

	@GetMapping("/Login")
	public CommonResult<UserGet> getUserByIdByPass(User user) throws Exception {
		return new CommonResult(200, "success", userService.getUserByIdByPass(user));
	}

	@GetMapping("/UserId")
	public CommonResult<Integer> getUserById(User user) throws Exception {
		return new CommonResult(200, "success", userService.getUserById(user.getUserId()));
	}
	
	@GetMapping("/UserName")
	public CommonResult<String> getUserNameById(User user) throws Exception {
		return new CommonResult(200, "success", userService.getUserNameById(user.getUserId()));
	}

	@PostMapping("/UserId")
	public CommonResult<Integer> saveUser(User user) throws Exception {
		return new CommonResult(200, "success", userService.saveUser(user));
	}

	@PutMapping("/UserId")
	public CommonResult<Integer> updateUser(User user) throws Exception {
		return new CommonResult(200, "success", userService.updateUser(user));
	}

	// delete
	@DeleteMapping("/UserId")
	public CommonResult<Integer> removeUser(User user) throws Exception {
		return new CommonResult(200, "success", userService.removeUser(user.getUserId()));
	}
}